<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class Member extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'email' => 'bail|required|email',
            'username' => 'bail|required|min:1|max:8',
            'pass' => 'bail|required|min:6|max:24',
            'repass' => ['bail','required','min:6','max:24',function ($attribute, $value, $fail) {
                if ($value !== $this->all()['pass']) {
                    return $fail('两次密码不一致');
                }
            }],
        ];
    }

    public function messages()
    {
        return [
            'email.required'=>'请填写邮箱',
            'email.email'   =>'邮箱格式不正确',
            'username.required'=> '请填写用户名',
            'username.min'=> '用户名最小长度为8',
            'username.max'=> '用户名最大长度为24',
        ];
    }
}
